import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
import {
  getHouseList
} from "../api"

export default new Vuex.Store({
  state: {
    userInfo:{},
    routerList:[],
    houseList:[],
    pages:{
      pageSize:10,
      pageIndex:1,
      total:0
    }
  },
  mutations: {
    CHANGE_USER_INFO(state,data){
      state.userInfo=data
    },
    CHANGE_ROUTER_LIST(state,data){
      state.routerList=data
    },
    CHANGE_HOUSE_LIST(state,data){
      state.houseList=data
    },
    CHANGE_PAGES(state,data){
      statusbar.pages={
        ...data
      }
    }
  },
  actions: {
    getHouseList(context,data=context.state.pages){
      getHouseList(data).then(res=>{
        context.commit('CHANGE_HOUSE_LIST',res.data.list)
        context.commit('CHANGE_PAGES',{
          ...data,
          total:res.data.total
        })
      })
    }
  },
  modules: {
  }
})
